package selef.xiafan.dao;

import io.lettuce.core.dynamic.annotation.Param;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import selef.xiafan.entity.system.Category;

import java.util.List;

public interface CategoryDao extends JpaRepository<Category, Integer> {
    List<Category> findAll();

    Category findById(int id);

    @Query(value = "SELECT COUNT(*) FROM t_category", nativeQuery = true)
    Long countAll();

    @Query(value = "SELECT * FROM t_category LIMIT :page,:size", nativeQuery = true)
    List<Category> findAllNoQuery(@Param("page") Integer page, @Param("size") Integer size);

    @Query(value = "SELECT * FROM t_category WHERE name LIKE CONCAT('%',:categoryQueryName,'%') LIMIT :page,:size ",nativeQuery = true)
    List<Category> findAllByQuery(@Param("page") Integer page, @Param("size") Integer size, @Param("name") String categoryQueryName);

    @Query(value = "SELECT COUNT(*) FROM t_category WHERE name LIKE CONCAT('%',:categoryQueryName,'%')", nativeQuery = true)
    Long countAllByQuery(@Param("name")String categoryQueryName);
}
